﻿using System.Collections.Generic;
using System.Linq;
using Coleotrack.Data.Contracts;

namespace Coleotrack.Data
{
    public class Project : Entity, IValidation
    {
        public Project()
        {
            ContactPerson = new User();
        }

        public virtual string Abbreviation
        {
            get;
            set;
        }

        public virtual string Name
        {
            get; set;
        }

        public virtual string Description
        {
            get; set;
        }

        public virtual User ContactPerson
        {
            get; set;
        }

        public virtual bool IsValid()
        {
            return GetRuleViolations().Count() == 0;
        }

        public virtual IEnumerable<RuleViolation> GetRuleViolations()
        {
            if (string.IsNullOrEmpty(Abbreviation))
            {
                yield return new RuleViolation("Abbreviation", "Abbreviation is required");
            }

            if (Abbreviation != null && Abbreviation.Length > 5)
            {
                yield return new RuleViolation("Abbreviation", "Abbreviation is to long");
            }

            if (string.IsNullOrEmpty(Name))
            {
                yield return new RuleViolation("Name", "Name is required");
            }

            yield break;
        }
    }
}
